﻿#region Copyright (c) 2011, thinktecture (http://www.thinktecture.com)

/*
   thinktecture.UIAnnotations was developed by Jörg Neumann.
   Copyright (c) 2011, thinktecture (http://www.thinktecture.com).
   All rights reserved, comes as-is and without any warranty. Use of this
   source file is governed by the license which is contained in LICENSE.TXT 
   in the distribution.
*/

#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Diagnostics;

namespace Thinktecture.UIAnnotations
{
    internal static class TraceHelpers
    {
        public static void TraceInformation(TraceSource source, TraceId id, string message, params object[] args)
        {
            StringBuilder msg = new StringBuilder(id.ToString()).Append(": ").AppendFormat(message, args);
            source.TraceEvent(TraceEventType.Information, (int)id, msg.ToString());
        }

        public static void TraceWarning(TraceSource source, TraceId id, string method, string message, params object[] args)
        {
            StringBuilder msg = new StringBuilder(id.ToString()).Append(": ").AppendFormat(message, args);
            source.TraceEvent(TraceEventType.Warning, (int)id, msg.ToString());
        }

        public static string GetElementName(object obj)
        {
            if (obj == null)
                return "(null)";
            string name = null;
            if (obj is FrameworkElement)
                name = ((FrameworkElement)obj).Name;
            if (string.IsNullOrEmpty(name))
                name = obj.ToString();
            return name;
        }
    }

    internal enum TraceId : int
    {
        Annotations_Ctor,
        Annotations_RemoveElement,
        Annotations_DisposeCurrent,
        Annotations_GetAdornerDict,
        Annotations_GetAdorner,
        Annotations_GetTextBox,
        Annotations_AttachedPropertyChanged,
        Annotations_ApplyDataAnnotations,
        Annotations_ApplyDataAnnotation,
        Annotations_AdornerCreated,
        Annotations_AddDescriptionFocusHandler,
        Annotations_RemoveDescriptionFocusHandler,
        Annotations_ShowDescription
    }
}
